package com.guoheng.hazard.sys.service.impl.woZhongData;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.guoheng.hazard.sys.mapper.hazard.SensorDataMapper;
import com.guoheng.hazard.sys.model.dto.wuZhongData.SongGangDataDTO;
import com.guoheng.hazard.sys.model.entity.hazard.SensorData;
import com.guoheng.hazard.sys.service.wuZhongData.SongGangDataService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @program: cespimp-hazard-server
 * @description:
 * @author: fbl
 * @create: 2020-07-31 07:41
 **/
@Service
public class SongGangDataServiceImpl implements SongGangDataService {

    @Resource
    SensorDataMapper sensorDataMapper;
    private final static Long SONG_GANG_ENTERPRISE_ID = 2L;

    @Override
    public void songGangDataTransfer(JSONObject jsonObject) {

        JSONArray songGangData = jsonObject.getJSONArray("songGangData");
        List<SongGangDataDTO> songGangDataDTOS = songGangData.toJavaList(SongGangDataDTO.class);
        List<SensorData> sensorData = new ArrayList<>();
        songGangDataDTOS.forEach(e -> {
            SensorData data = new SensorData();
            data.setEntprId(SONG_GANG_ENTERPRISE_ID);
            BeanUtils.copyProperties(e, data);
            sensorData.add(data);
        });
        sensorDataMapper.insertSongGangData(sensorData);
    }
}
